///*******************************************************************************
//** Copyright (c) 2004 MaK Technologies, Inc.
//** All rights reserved.
//*******************************************************************************/
///*******************************************************************************
//** $RCSfile: simple1516.cxx,v $ $Revision: 1.6 $ $State: Exp $
//*******************************************************************************/
//
//// A simple federate that updates an object with attributes whose values
//// are the name of the attribute. Objects from other simple federates
//// are discovered and reflected. The string values are byte encoded to allow
//// compatiblity between 1.3 and 1516
//
//#pragma warning(disable: 4251)
//#pragma warning(disable: 4786)
//#pragma warning(disable: 4290)
//
//#ifdef WIN32
//#include <winsock2.h>
//#include <process.h>
//
//#if (_MSC_VER == 1200)
//// Test for XTREE patch in MSVC++ 6.0
//#include <XTREE>
//#ifdef _XTREE_
//#error FATAL_ERROR: You must install the Dinkumware XTREE patch before using HLA 1516 with MSVC++ 6.0
//#endif
//#endif
//#else
//
//#endif
//
//#include <stdio.h>
//#include <wchar.h>
//#include <sstream>
//#include <string>
//#include <iostream>
//#include <sstream>
//
////#include <RTI/RTI1516.h>
////#include <RTI/RTIambassadorFactory.h>
////#include <RTI/logicalTimeFactoryImpl.h>
//#include "rti.h"
//#include "fedAmb1516.h"
//#include "stringUtil.h"
//
//// Logical time factory implementation
////LogicalTimeFactoryImpl theTimeFactory;
//
//// Handles keyboard input without blocking
////keyboard input;
//
//using namespace rti1516;
//using namespace std;
//
//// Data shared between federate and federate ambassador
//DtTalkAmbData theAmbData;
//
//// The object class name
//std::wstring theClassName = L"BaseEntity";
//
//// The interaction class name
//std::wstring theInterClassName = L"WeaponFire";
//
//
//////////////////////////////////////////////////////////////////////////////////
//// Create the federation execution
//void createFedEx(RTIambassador & rtiAmb,
//                 std::wstring const& fedName)
//{
//   wcout << L"createFederationExecution "
//         << fedName.c_str() << endl;
//
//   rtiAmb.createFederationExecution(fedName);
//
//
//   wcout << L"Federation Created." << endl;
//}
//
//////////////////////////////////////////////////////////////////////////////////
//// Join the federation execution
//void joinFedEx(
//			   RTIambassador & rtiAmb, rti1516::FederateAmbassador & fedAmb,
//   std::wstring const& federateType, std::wstring const& federationName)
//{
//   bool joined=false;
//   const int maxTry  = 10;
//   int numTries = 0;
//   wcout << L"joinFederationExecution "
//         << federateType.c_str() << L" "
//         << federationName.c_str() << endl;
//
//   while (!joined && numTries++ < maxTry)
//   {
//         rtiAmb.joinFederationExecution(federateType, federationName, fedAmb);
//         joined = true;
//   }
//   if (joined)
//      wcout << L"Joined Federation." << endl;
//   else
//   {
//      wcout << L"Giving up." << endl;
//      rtiAmb.destroyFederationExecution(federationName);
//      exit(0);
//   }
//}
//
//////////////////////////////////////////////////////////////////////////////////
//// Resign and destroy the federation execution
//void resignAndDestroy( RTIambassador & rtiAmb,
//      std::wstring const& federationName)
//{
//   rtiAmb.resignFederationExecution();
//   rtiAmb.destroyFederationExecution(federationName);
//}
//
//////////////////////////////////////////////////////////////////////////////////
//// Publish and subscribe the object class attributes.
//// Register an object instance of the class.
//bool publishSubscribeAndRegisterObject(RTIambassador & rtiAmb)
//{
//	return false;
//}
//
//////////////////////////////////////////////////////////////////////////////////
//// Publish and Subscribe to an interaction class
//bool publishAndSubscribeInteraction(RTIambassador & rtiAmb)
//{
//	return false;
//}
//
//
//int main(int argc, char** argv)
//{
//      std::wstring federationName(L"MAKsimple");
//      std::wstring federationFile(L"MAKsimple.xml");
//      std::wstring federateType(L"rtisimple1516");
//
////    RTI and Federate Ambassadors
////    RTIambassadorFactory* rtiAmbFactory = new RTIambassadorFactory();
//      std::auto_ptr < RTIambassador > rtiAmbAP = NULL;
////	  rtiAmbFactory->createRTIambassador(args);
//      RTIambassador* rtiAmb = rtiAmbAP.release();
//	  rti1516::FederateAmbassador fedAmb;
//      // Create the federation
//      createFedEx(*rtiAmb, federationName);
//
//      // Join the federation
//      joinFedEx(*rtiAmb, fedAmb, federateType, federationName);
//
//      // Publish, subscribe and register and object
//      if (!publishSubscribeAndRegisterObject(*rtiAmb))
//      {
//         resignAndDestroy(*rtiAmb, federationName);
//         return 0;
//      }
//
//      // Publish and subscribe to the required interaction
//      if (!publishAndSubscribeInteraction(*rtiAmb))
//      {
//         resignAndDestroy(*rtiAmb, federationName);
//         return 0;
//      }
//
//#ifdef WIN32
//      WSADATA data;
//      WSAStartup(MAKEWORD(1,1), &data);
//#endif      
//      long count=0;
//      while (1)
//      {
//         std::stringstream ss;
//         ss << "1516-" << count++;
//         std::string tag(ss.str());
//         // Tag format is narrow string representation compatible
//         // with 1.3 simple federate
//
//         // Update the object
//         rtiAmb->updateAttributeValues();    
//      }
//
//      // Resign and destroy federation
//      resignAndDestroy(*rtiAmb, federationName);
//
//#ifdef WIN32
//   WSACleanup();
//#endif
//
//   return 0;
//
//}
//
